package cn.tom.basic.exception;

import lombok.Getter;

/**
 * 自定义业务异常
 */
public class BusinessException extends RuntimeException {
    @Getter
    private final StatusCode statusCode;

    // 保留原始异常堆栈
    public BusinessException(StatusCode statusCode) {
        super(statusCode.getMessage()); // 关键：设置父类message
        this.statusCode = statusCode;
    }

    // 支持自定义错误消息
    public BusinessException(StatusCode statusCode, String customMessage) {
        super(customMessage != null ? customMessage : statusCode.getMessage());
        this.statusCode = statusCode;
    }
}
